/**
 * Created by jiachneyu on 2018/3/22.
 */
const db = require('../db.js');


const loginHandle = async (name, pwd) => {
    let returnJson = {};
    const collection = db.get('user');
    return await collection.find({name: name, password: pwd}).then((res) => {
        console.log(res)
        db.close();
        if (res.length > 0) {
            return returnJson = {
                code: 1,
                msg: "登录成功"
            }
        }
        else {
            return returnJson = {
                code: 0,
                msg: "用户名或密码错误"
            }
        }
    }).catch(err => {
        console.log(err);
        db.close();
        return returnJson = {
            code: -1,
            msg: '网络不稳定'
        };
    })
}

module.exports = loginHandle;